/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package academia.gui;

import academia.gui.lista.ListarCliente;
import academia.persistencia.DBAcademia;
import academia.persistencia.IDregistro;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;

/**
 *
 * @author Renan
 */
public class TelaFichaTreino extends javax.swing.JFrame {

    Connection conn=null;
    ResultSet rs =null;
    PreparedStatement ps=null;
    
    public TelaFichaTreino() {
        initComponents();
        conn=DBAcademia.ConnectDB();
        Update_Table();
    }
    
    
    private void Update_Table(){
   
    try{
       String sql= "SELECT Ficha FROM Treino WHERE IDaluno=?";
       ps=conn.prepareStatement(sql);
       ps.setInt(1,IDregistro.getId2());
       
       rs=ps.executeQuery();
       
       if(rs.next()){
               
               fichas.setModel(DbUtils.resultSetToTableModel(rs));
             }else{
               JOptionPane.showMessageDialog(null,"O aluno nao possui fficha de treino.","Erro",JOptionPane.ERROR_MESSAGE);
             
           }
       
    
    }catch(Exception e){
        JOptionPane.showMessageDialog(null,e);
        
    }finally{
                 try {
                      rs.close();
                      ps.close();
                      } catch (SQLException ex) {
                            Logger.getLogger(ListarCliente.class.getName()).log(Level.SEVERE, null, ex);
                      }
    }
    
}
    
    

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnVoltar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        fichas = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btnVoltar.setText("Voltar");
        btnVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVoltarActionPerformed(evt);
            }
        });

        fichas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(fichas);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(189, 189, 189)
                .addComponent(btnVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnVoltar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVoltarActionPerformed
        new TelaInstrutor().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_btnVoltarActionPerformed

   
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnVoltar;
    private javax.swing.JTable fichas;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables
}
